package com.nenglai.admin.modular.report.form;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author kongdehui
 * @date 2021/06/18 15:55
 **/
@Data
public class TemplateForm {

    private Long id;

    /**
     * 名称
     */
    @NotEmpty
    private String name;

    /**
     * 描述
     */
    private String remark;

    /**
     * 排序
     */
    @NotNull
    private Integer sort;

    /**
     * 导出模板名称
     */
    @NotEmpty
    private String outputTemplate;

    /**
     * 存储服务
     */
    @NotEmpty
    private String service;

    public String getUploadService() {
        return StringUtils.isEmpty(service) ? "localUpload" : service;
    }

    public String getUploadPath(String localPath) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        String format = sdf.format(new Date());
        String service = getUploadService();
        if ("cosUpload".equals(service)) {
            return "upload/" + format;
        }
        return localPath + "/" + format;
    }
}
